using System;
using System.Collections.Generic;
using System.Text;
using Curchy.PERTToolbox.Interface;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;
using Curchy.PERTToolbox.PropertyGrid;

namespace Curchy.PERTToolbox.Entity
{
    public class Risk : IDescriptive
    {
        private string _name;
        private string _detail;
        private int _riskOccurance;
        private TimeSpan _contengency;

        [PropertyOrder(1)]
        [CategoryAttribute("Specifications")]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        [PropertyOrder(2)]
        [CategoryAttribute("Specifications")]
        public string Detail
        {
            get { return _detail; }
            set { _detail = value; }
        }

        [PropertyOrder(3)]
        [CategoryAttribute("Data")]
        public int RiskOccurance
        {
            get { return _riskOccurance; }
            set { _riskOccurance = value; }
        }

        [XmlIgnore]
        [PropertyOrder(4)]
        [CategoryAttribute("Data")]
        public TimeSpan Contengency
        {
            get { return _contengency; }
            set { _contengency = value; }
        }

        [Browsable(false)]
        [XmlElement("Contengency", DataType = "duration")]
        public string SerializableContengency
        {
            get
            {
                return XmlConvert.ToString(_contengency);
            }
            set
            {
                _contengency = XmlConvert.ToTimeSpan(value);
            }
        }

        public override string ToString()
        {
            return _name;
        }

        #region IDescriptive Members

        [Browsable(false)]
        public string Description
        {
            get 
            { 
                string toReturn = "Occurence : " + _riskOccurance +"%";
                if(_contengency != null)
                    toReturn += ", with " + _contengency.ToString() + " of contengency"; 
                return toReturn;
            }
        }

        #endregion
    }
}
